from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep

driver = webdriver.Firefox()
driver.get('http://sahitest.com/demo/index.htm')
print(driver.current_window_handle) #查看当前窗口句柄  cc164244-c7cd-43e5-8500-673acd7ee190
sleep(2)
driver.find_element(By.LINK_TEXT, 'Window Open Test').click()   #打开新窗口
print(driver.window_handles)  # 打印所有窗口句柄['cc164244-c7cd-43e5-8500-673acd7ee190', '2217ece5-ec34-451d-a96f-742e590e31e4']
sleep(2)
driver.close()  #close关闭当前active窗口
print(driver.window_handles)   #第一个窗口90关闭，第二个还在
sleep(2)
driver.quit()

